﻿// ***********************************************************************
// Provided for Informational Purposes Only
//
// Apache 2.0 License
//
// Licensed under the Apache License, Version 2.0 (the "License"); you may
// not use this file except in compliance with the License. You may obtain
// a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 
//
// THIS CODE IS PROVIDED *AS IS* BASIS, WITHOUT WARRANTIES OR CONDITIONS OF
// ANY KIND, EITHER EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION ANY 
// IMPLIED WARRANTIES OR CONDITIONS OF TITLE, FITNESS FOR A PARTICULAR 
// PURPOSE, MERCHANTABLITY OR NON-INFRINGEMENT.
//
// See the Apache Version 2.0 License for specific language governing
// permissions and limitations under the License.
// ***********************************************************************
// Assembly  : ContractMeow.Models
// File      : Group.cs
//
// ***********************************************************************
using ContractMeow.Api.Dtos.AutoComplete;
using ContractMeow.Api.Dtos.References;
using System;
using YammerApi = ContractMeow.Api.Dtos;


namespace ContractMeow.Models
{
	public sealed class Group
	{
		public Group() { }

		public Group(YammerApi.Group group)
		{
			Id = group.Id;
			Name = group.Name;
			FullName = group.FullName;
			Description = group.Description;
		}

		public Group(GroupReference groupRef)
		{
			this.Description = groupRef.Description;
			this.FullName = groupRef.FullName;
			this.Id = groupRef.Id;
			this.Name = groupRef.Name;
		}

		public Int64 Id { get; set; }

		private String _name;
		public String Name
		{
			get { return _name; }
			set
			{
				_name = value;
			}
		}

		private String _fullName;
		public String FullName
		{
			get { return _fullName; }
			set
			{
				_fullName = value;
			}
		}

		private String _description;
		public String Description
		{
			get { return _description; }
			set
			{
				_description = value;
			}
		}

		private Uri _mugshotUrl;
		public Uri MugshotUrl
		{
			get { return _mugshotUrl; }
			set
			{
				_mugshotUrl = value;
			}
		}

		public Boolean IsAllCompany { get { return Id == 0; } }

		/// <summary>
		/// Performs an implicit conversion from <see cref="Group" /> to <see cref="YammerApi.Group" />.
		/// </summary>
		public static implicit operator YammerApi.Group(Group group)
		{
			return new YammerApi.Group()
				{
					Id = group.Id,
					Name = group.Name,
					FullName = group.FullName,
					Description = group.Description,
					MugshotUrl = group.MugshotUrl,
				};
		}

		/// <summary>
		/// Performs an explicit conversion from <see cref="YammerApi.Group" /> to <see cref="Group" />.
		/// </summary>
		public static explicit operator Group(YammerApi.Group group)
		{
			return new Group(group);
		}

		public static implicit operator AutoCompleteGroup(Group group)
		{
			return new AutoCompleteGroup()
				{
					Id = group.Id,
					Name = group.Name,
					GroupName = group.FullName,
					Description = group.Description,
					MugshotUrl = group.MugshotUrl,
				};
		}

		/// <summary>
		/// Performs an explicit conversion from <see cref="AutoCompleteGroup" /> to <see cref="Group" />.
		/// </summary>
		public static explicit operator Group(AutoCompleteGroup group)
		{
			return new Group()
				{
					Name = group.Name,
					FullName = group.GroupName,
					Id = group.Id,
					Description = group.Description,
					MugshotUrl = group.MugshotUrl,
				};
		}
	}
}